<?php
namespace app\mini\controller\commons;

use app\common\model\CarBrands;
use app\common\model\CarModels;
use app\common\model\CarSeries as seriesModel;
use app\common\model\ServiceMainBusiness;
use app\common\model\SweptVolume;
use app\common\traits\InterfacesExceptionTrait;
use think\Env;
use think\Log;

class Car extends Base
{

    use InterfacesExceptionTrait;

    /**
     * 二手车参数
     * @return array
     * @throws \think\exception\DbException
     */
    public function car_params()
    {
        $swept_volume =SweptVolume::field('id,name')->select();
        $arr = [
            'energy_type' => [//能源类型
                ['id' => 1, 'name' => '燃油车', 'extend' => true],
                ['id' => 2, 'name' => '电动车', 'extend' => false],
                ['id' => 3, 'name' => '混动车', 'extend' => true]
            ],
            'level' => [ //级别
                ['id' => 1, 'name' => '小型车'],
                ['id' => 2, 'name' => '中型车'],
                ['id' => 3, 'name' => '大型车']
            ],
            'discharge' => [//排放标准
                ['id' => 1, 'name' => '国1'],
                ['id' => 2, 'name' => '国2'],
                ['id' => 3, 'name' => '国3'],
                ['id' => 4, 'name' => '国4'],
                ['id' => 5, 'name' => '国5'],
                ['id' => 6, 'name' => '国6'],
            ],
            'gearbox' => [//变速箱
                ['id' => 1, 'name' => '自动'],
                ['id' => 2, 'name' => '手动'],
            ],
            'swept_volume' => $swept_volume,//排量

        ];
        return $this->response($arr);
    }


    /**
     * 获取指定商机对应的搜索条件
     * @return array
     * @throws \think\exception\DbException
     */
    public function condition()
    {
        $service_type = input('service_type',1);
        if ($service_type == 1){
            $arr = [
                ['name' => '默认排序','state'=>false, 'type' => 'list', 'list' => [
                    ['name' => '默认排序','state'=>false, 'key' => 'sort', 'id' => 0],
                    ['name' => '最新上架','state'=>false, 'key' => 'sort', 'id' => 1],
                    ['name' => '里程最少','state'=>false, 'key' => 'sort', 'id' => 2],
                    ['name' => '价格最低','state'=>false, 'key' => 'sort', 'id' => 3],
                    ['name' => '车龄最短','state'=>false, 'key' => 'sort', 'id' => 4]]
                ],
                ['name' => '品牌', 'state'=>false, 'type' => 'url', 'key' => 'models_id', 'url' => Env::get('app.app_host') . "/mini/car_brand/index"],
                ['name' => '归属','state'=>false,  'type' => 'list', 'list' => [
                    ['name' => '全部','state'=>false, 'key' => 'belong', 'id' => 0],
                    ['name' => '个人', 'state'=>false,'key' => 'belong', 'id' => 1],
                    ['name' => '车商','state'=>false, 'key' => 'belong', 'id' => 2],
                    ['name' => '我发布的','state'=>false, 'key' => 'belong', 'id' => 3],
                ]],
                ['name' => '更多筛选','state'=>false,  'type' => 'list', 'list' => [
                    ['name' => '车龄区间（年）', 'state'=>false,'key' => 'car_age', 'type' => 'between', 'value' => ['min'=>0,'max'=>30,'step'=>1]],
                    ['name' => '价格区间（万元）','state'=>false, 'key' => 'price', 'type' => 'between', 'value' => ['min'=>0,'max'=>100,'step'=>1]],
                    ['name' => '里程区间（万公里）','state'=>false, 'key' => 'mileage', 'type' => 'between', 'value' => ['min'=>0,'max'=>50,'step'=>1]],
                    ['name' => '车辆级别','state'=>false, 'type' => 'list', 'list' => [
                        ['name' => '全部', 'state'=>false,'key' => 'level', 'id' => 0],
                        ['name' => '小型车', 'state'=>false,'key' => 'level', 'id' => 1],
                        ['name' => '中型车','state'=>false, 'key' => 'level', 'id' => 2],
                        ['name' => '大型车','state'=>false, 'key' => 'level', 'id' => 3],
                    ]],
                    ['name' => '能源类别','state'=>false, 'type' => 'list', 'list' => [
                        ['name' => '全部','state'=>false, 'key' => 'car_type', 'id' => 0],
                        ['name' => '燃油车','state'=>false, 'key' => 'car_type', 'id' => 1],
                        ['name' => '混动车', 'state'=>false,'key' => 'car_type', 'id' => 2],
                        ['name' => '电动车', 'state'=>false,'key' => 'car_type', 'id' => 3],
                    ]],
                ]],
            ];
        }else{
            if ($service_type == 2){
                $list = ServiceMainBusiness::where(['service_type'=>$service_type,'status'=>1,'is_del'=>0])->select()->toArray();
                $arr[] = ['name'=>'全部','state'=>false,'key'=>'sort','id'=>0];
                foreach ($list as $v){
                    $arr[] =  ['name'=>$v['name'],'state'=>false,'key'=>'sort','id'=>$v['id']];
                }
            }else{
                $arr = [['name'=>'默认排序','state'=>false,'type'=>'list','list'=>[
                    ['name'=>'最新上架','state'=>false,'key'=>'sort','id'=>1],
                    ['name'=>'我发布的','state'=>false,'key'=>'sort','id'=>2],
                    ['name'=>'距离优先','state'=>false,'key'=>'sort','id'=>3]
                ]]];
            }
            /*$list = ServiceMainBusiness::where(['service_type'=>$service_type,'status'=>1,'is_del'=>0])->select()->toArray();
            if (!empty($list)){
                $arr[] = ['name'=>'全部','state'=>false,'key'=>'sort','id'=>0];
                foreach ($list as $v){
                    $arr[] =  ['name'=>$v['name'],'state'=>false,'key'=>'sort','id'=>$v['id']];
                }
            }else{
                $arr = [['name'=>'默认排序','state'=>false,'type'=>'list','list'=>[
                    ['name'=>'最新上架','state'=>false,'key'=>'sort','id'=>1],
                    ['name'=>'我发布的','state'=>false,'key'=>'sort','id'=>2],
                    ['name'=>'距离优先','state'=>false,'key'=>'sort','id'=>3]
                ]]];
            }*/
        }


//        switch ($service_type)
//        {
//            case 1://二手车
//                $arr = [
//                    ['name' => '默认排序','state'=>false, 'type' => 'list', 'list' => [
//                        ['name' => '默认排序','state'=>false, 'key' => 'sort', 'id' => 0],
//                        ['name' => '最新上架','state'=>false, 'key' => 'sort', 'id' => 1],
//                        ['name' => '里程最少','state'=>false, 'key' => 'sort', 'id' => 2],
//                        ['name' => '价格最低','state'=>false, 'key' => 'sort', 'id' => 3],
//                        ['name' => '车龄最短','state'=>false, 'key' => 'sort', 'id' => 4]]
//                    ],
//                    ['name' => '品牌', 'state'=>false, 'type' => 'url', 'key' => 'models_id', 'url' => Env::get('app.app_host') . "/mini/car_brand/index"],
//                    ['name' => '归属','state'=>false,  'type' => 'list', 'list' => [
//                        ['name' => '全部','state'=>false, 'key' => 'belong', 'id' => 0],
//                        ['name' => '个人', 'state'=>false,'key' => 'belong', 'id' => 1],
//                        ['name' => '车商','state'=>false, 'key' => 'belong', 'id' => 2],
//                        ['name' => '我发布的','state'=>false, 'key' => 'belong', 'id' => 3],
//                    ]],
//                    ['name' => '更多筛选','state'=>false,  'type' => 'list', 'list' => [
//                        ['name' => '车龄区间（年）', 'state'=>false,'key' => 'car_age', 'type' => 'between', 'value' => ['min'=>0,'max'=>30,'step'=>1]],
//                        ['name' => '价格区间（万元）','state'=>false, 'key' => 'price', 'type' => 'between', 'value' => ['min'=>0,'max'=>100,'step'=>1]],
//                        ['name' => '里程区间（万公里）','state'=>false, 'key' => 'mileage', 'type' => 'between', 'value' => ['min'=>0,'max'=>50,'step'=>1]],
//                        ['name' => '车辆级别','state'=>false, 'type' => 'list', 'list' => [
//                            ['name' => '全部', 'state'=>false,'key' => 'level', 'id' => 0],
//                            ['name' => '小型车', 'state'=>false,'key' => 'level', 'id' => 1],
//                            ['name' => '中型车','state'=>false, 'key' => 'level', 'id' => 2],
//                            ['name' => '大型车','state'=>false, 'key' => 'level', 'id' => 3],
//                        ]],
//                        ['name' => '能源类别','state'=>false, 'type' => 'list', 'list' => [
//                            ['name' => '全部','state'=>false, 'key' => 'car_type', 'id' => 0],
//                            ['name' => '燃油车','state'=>false, 'key' => 'car_type', 'id' => 1],
//                            ['name' => '混动车', 'state'=>false,'key' => 'car_type', 'id' => 2],
//                            ['name' => '电动车', 'state'=>false,'key' => 'car_type', 'id' => 3],
//                        ]],
//                    ]],
//                ];
//                break;
//            case 2://
//
//                $arr = [
//                    ['name'=>'全部','state'=>false,'key'=>'sort','id'=>0],
//                    ['name'=>'搭电/电瓶更换','state'=>false,'key'=>'sort','id'=>1],
//                    ['name'=>'补胎/换胎','state'=>false,'key'=>'sort','id'=>2],
//                    ['name'=>'拖车','state'=>false,'key'=>'sort','id'=>20]];
//                break;
//            default:
//                $arr = [
//                    ['name' => '默认排序', 'state' => false, 'type' => 'list', 'list' =>
//                        [
//                            ['name' => '最新上架', 'state' => false, 'key' => 'sort', 'id' => 1],
//                            ['name' => '我发布的', 'state' => false, 'key' => 'sort', 'id' => 2],
//                            ['name' => '距离优先', 'state' => false, 'key' => 'sort', 'id' => 3]
//                        ]
//                    ]
//                ];
//        }
        return $this->response($arr);
    }

}